﻿using System.ComponentModel;
using System.Windows;

namespace NanoMvvm
{
    /// <summary>
    /// Can be used to resolve whether the application is currently in design
    /// mode.
    /// </summary>
    public static class RunModeResolver
    {
        private static bool? isInDesignMode;

        /// <summary>
        /// Gets a value indicating whether the control is in design mode (running in Blend
        /// or Visual Studio).
        /// </summary>
        public static bool InDesignMode
        {
            get
            {
                if (!isInDesignMode.HasValue)
                {
#if SILVERLIGHT
                    _isInDesignMode = DesignerProperties.IsInDesignTool;
#else
                    var prop = DesignerProperties.IsInDesignModeProperty;

                    isInDesignMode = (bool) DependencyPropertyDescriptor
                        .FromProperty(prop, typeof(FrameworkElement)).Metadata.DefaultValue;
#endif
                }

                return isInDesignMode.Value;
            }
        }
    }
}